package request

import "github.com/astaxie/beego/validation"

type AddrRequest struct {
	AddrId     uint   `json:"addrId"`                        //地址ID
	Receiver   string `json:"receiver" binding:"required"`   //收货人 必填
	Addr       string `json:"addr" binding:"required"`       //地址 必填
	PostCode   string `json:"postCode"`                      //邮编
	Mobile     string `json:"mobile" binding:"required"`     //手机 必填
	ProvinceId uint   `json:"provinceId" binding:"required"` //省ID 必填
	CityId     uint   `json:"cityId" binding:"required"`     //城市ID 必填
	AreaId     uint   `json:"areaId" binding:"required"`     //区ID 必填
	Province   string `json:"province" binding:"required"`   //省 必填
	City       string `json:"city" binding:"required"`       //城市 必填
	Area       string `json:"area" binding:"required"`       //区 必填
}

func (a *AddrRequest) Valid(v *validation.Validation) {
	if a.Receiver == "" {
		v.SetError("Receiver", "收货人不能为空")
	} else if a.Addr == "" {
		v.SetError("Addr", "地址不能为空")
	} else if a.Mobile == "" {
		v.SetError("Mobile", "手机不能为空")
	} else if a.ProvinceId <= 0 {
		v.SetError("ProvinceId", "省ID不能为空")
	} else if a.CityId <= 0 {
		v.SetError("CityId", "城市ID不能为空")
	} else if a.AreaId <= 0 {
		v.SetError("AreaId", "区ID不能为空")
	} else if a.Province == "" {
		v.SetError("Province", "省不能为空")
	} else if a.City == "" {
		v.SetError("City", "城市不能为空")
	} else if a.Area == "" {
		v.SetError("Area", "区不能为空")
	}
}
